﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Project;
    namespace IHMainApp
    {
        public partial class ProjectCustomForm : Form
        {

            public ProjectData BackUpConfig { set; get; }

            public ProjectCustomForm()
            {
                InitializeComponent();
            }

            private void ProjectCustomForm_Load(object sender, EventArgs e)
            {
                NewFileTypeLB.SelectedIndex = 0;
            }

            private void radioButton1_CheckedChanged(object sender, EventArgs e)
            {
                radioButton2.Checked = !radioButton1.Checked;
                NewFileGB.Enabled = radioButton1.Checked;
                ExistFileGB.Enabled = radioButton2.Checked;
            }

            private void radioButton2_CheckedChanged(object sender, EventArgs e)
            {
                radioButton1.Checked = !radioButton2.Checked;
                NewFileGB.Enabled = radioButton1.Checked;
                ExistFileGB.Enabled = radioButton2.Checked;
            }

            private void NewFileTypeLB_SelectedIndexChanged(object sender, EventArgs e)
            {
                var arr = new string[3] { ".lpm", ".cycle", ".state" };
                ExtLabel.Text = arr[NewFileTypeLB.SelectedIndex];
            }

            private void BrowseButton_Click(object sender, EventArgs e)
            {
                var dial = new OpenFileDialog();
                dial.AddExtension = true;
                dial.CheckFileExists = false;
                dial.Filter = "Файлы LPMED  | *.lpm | Файлы циклограмм | *.cycle | Файлы машины состояний | *.state";                
                if (dial.ShowDialog() == DialogResult.OK)
                    PathLabel.Text = dial.FileName;
            }

            private void AddButton_Click(object sender, EventArgs e)
            {
                if (radioButton1.Checked)
                {
                    if (textBox1.Text.Trim() == "")
                    {
                        var mess = MessageBox.Show("Введите имя!");
                        return;
                    }
                    //Create new ICodeFile item
                    //ConfigManager.AddNewItem(n);
                }
                else
                { 
                    if (PathLabel.Text == "")
                    {
                        var mess = MessageBox.Show("Укажите путь к файлу!");
                        return;
                    }
                    //Add path:
                    //TODO: What it is ?
                    //ProjectManager.CurrentProject.Files.Add(PathLabel.Text);
                    //Open document....
                }
            }

            private void OkButton_Click(object sender, EventArgs e)
            {
                this.Close();
            }

            private void CancelButton_Click(object sender, EventArgs e)
            {
                //TODO: What it is ?
                //ConfigManager.CurrentProject = BackUpConfig;
                this.Close();
            }
        }
    }
